﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Master/SiteContent.Master" AutoEventWireup="true"
    CodeBehind="Distributors.aspx.cs" Inherits="Warehouse.Web.Management.Distributors" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .moduleheader .moduleheadertoolbar > * {
            margin: 16px 5px 0 5px;
        }
        .datatable {
            min-width: 100%;
        }
        .col_name {
        }
        .col_code {
        }
        .col_postaddr {
        }
        .col_postcode {
            width: 46px;
        }
        .col_consignee {
            width: 50px;
        }
        .col_telephone {
            width: 80px;
        }
        .col_email {
            width: 100px;
        }
        .col_house {
            width: 60px;
        }
        .col_op {
            width: 60px;
        }
    </style>

    <script type="text/javascript">
        var HOUSES = [];
        function addItem() {
            var html = ['<div class="dialog">'];
            html.push('<table class="infotable">');
            html.push('<tr><td><label>公司名</label></td><td><input type="text" field="Name"/></td></tr>');
            html.push('<tr><td><label>代码</label></td><td><input type="text" field="Code"/></td></tr>');
            html.push('<tr><td><label>地址</label></td><td><input type="text" field="PostAddress"/></td></tr>');
            html.push('<tr><td><label>邮编</label></td><td><input type="text" field="PostCode"/></td></tr>');
            html.push('<tr><td><label>收货人</label></td><td><input type="text" field="Consignee"/></td></tr>');
            html.push('<tr><td><label>电话</label></td><td><input type="text" field="Telephone"/></td></tr>');
            html.push('<tr><td><label>Email</label></td><td><input type="text" field="Email"/></td></tr>');
            html.push('<tr><td><label>默认仓库</label></td><td><select field="DefaultHouseID">');
            $.each(HOUSES, function(index) {
                html.push('<option value="' + this.ID + '"');
                if (index == 0) {
                    html.push(' selected="selected" ');
                }
                html.push('>' + this.Name + '</option>');
            });
            html.push('</select></td></tr>');
            html.push('</table>');
            html.push('</div>');
            var dialog = top.showDialog(html.join(''), { title: "添加客户",
                width: 300,
                height: 350,
                resizable: false,
                modal: true,
                buttons: {
                    "确定": function() {
                        var data = Util.getFields(dialog);
                        if (!data.Name) {
                            alert("请输入公司名");
                            return;
                        }
                        data.HouseType = data.HouseType - 0;
                        Util.post("", $.extend(true, { action: "Add" }, data), function(succeed, data, err) {
                            if (succeed) {
                                alert('保存成功');
                                dialog.dialog('close');
                                window.location.reload();
                            } else {
                                alert(err);
                            }
                        }, { autoOverlay: true });
                    },
                    "取消": function() {
                        dialog.dialog('close');
                    }
                }
            });
        }
        function modifyItem(distributorId) {
            Util.get("", { action: "Get", DistributorID: distributorId }, function(succeed, data, err) {
                if (succeed) {
                    var html = ['<div class="dialog">'];
                    html.push('<table class="infotable">');
                    html.push('<tr><td><label>公司名</label></td><td><input type="hidden" field="ID" value="' + data.ID + '"/><input type="text" field="Name" value="' + data.Name + '"/></td></tr>');
                    html.push('<tr><td><label>代码</label></td><td><input type="text" field="Code" value="' + data.Code + '"/></td></tr>');
                    html.push('<tr><td><label>地址</label></td><td><input type="text" field="PostAddress" value="' + data.PostAddress + '"/></td></tr>');
                    html.push('<tr><td><label>邮编</label></td><td><input type="text" field="PostCode" value="' + data.PostCode + '"/></td></tr>');
                    html.push('<tr><td><label>收货人</label></td><td><input type="text" field="Consignee" value="' + data.Consignee + '"/></td></tr>');
                    html.push('<tr><td><label>电话</label></td><td><input type="text" field="Telephone" value="' + data.Telephone + '"/></td></tr>');
                    html.push('<tr><td><label>Email</label></td><td><input type="text" field="Email" value="' + data.Email + '"/></td></tr>');
                    html.push('<tr><td><label>默认仓库</label></td><td><select field="DefaultHouseID">');
                    $.each(HOUSES, function(index) {
                        html.push('<option value="' + this.ID + '"');
                        if (this.ID == data.DefaultHouseID) {
                            html.push(' selected="selected" ');
                        }
                        html.push('>' + this.Name + '</option>');
                    });
                    html.push('</select></td></tr>');
                    html.push('</table>');
                    html.push('</div>');
                    var dialog = top.showDialog(html.join(''), { title: "编辑客户",
                        width: 300,
                        height: 350,
                        resizable: false,
                        modal: true,
                        buttons: {
                            "确定": function() {
                                var data = Util.getFields(dialog);
                                if (!data.Name) {
                                    alert("请输入公司名");
                                    return;
                                }
                                data.HouseType = data.HouseType - 0;
                                Util.post("", $.extend(true, { action: "Save" }, data), function(succeed, data, err) {
                                    if (succeed) {
                                        alert('保存成功');
                                        dialog.dialog('close');
                                        window.location.reload();
                                    } else {
                                        alert(err);
                                    }
                                }, { autoOverlay: true });
                            },
                            "取消": function() {
                                dialog.dialog('close');
                            }
                        }
                    });
                } else {
                    alert(err);
                }
            }, { autoOverlay: true });
        }
        function deleteItem(distributorId) {
            if (confirm("您确认要删除该客户吗？")) {
                Util.post("", { action: "Delete", DistributorID: distributorId }, function(succeed, data, err) {
                    if (succeed) {
                        alert('删除成功');
                        window.location.reload();
                    } else {
                        alert(err);
                    }
                }, { autoOverlay: true });
            }
        }

        $(function() {
            HOUSES = eval('(' + document.getElementById('allhouses').innerHTML + ')');
        });
    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="moduleheader">
        <h4>
            客户管理</h4>
        <div class="moduleheadertoolbar">
            <input type="button" class="ui-button-refresh" onclick="window.location.reload();"
                value="刷新" />
            <uc:AuthorityControl runat="server" Action="Add">
                <input type="button" class="ui-button-add" onclick="addItem();" value="添加客户" />
            </uc:AuthorityControl>
        </div>
    </div>
    <div class="modulecontent">
        <table class="datatable">
            <tr>
                <th class="col_name">
                    公司名
                </th>
                <th class="col_code">
                    代码
                </th>
                <th class="col_postaddr">
                    地址
                </th>
                <th class="col_postcode">
                    邮编
                </th>
                <th class="col_consignee">
                    收货人
                </th>
                <th class="col_telephone">
                    电话
                </th>
                <th class="col_email">
                    Email
                </th>
                <th class="col_house">
                    默认仓库
                </th>
                <th class="col_op">
                    管理
                </th>
            </tr>
            <asp:Repeater ID="rptDistributors" runat="server">
                <ItemTemplate>
                    <tr>
                        <td class="col_name">
                            <%# Eval("Distributor.Name")%>
                        </td>
                        <td class="col_code">
                            <%# Eval("Distributor.Code")%>
                        </td>
                        <td class="col_postaddr">
                            <%# Eval("Distributor.PostAddress")%>
                        </td>
                        <td class="col_postcode">
                            <%# Eval("Distributor.PostCode")%>
                        </td>
                        <td class="col_consignee">
                            <%# Eval("Distributor.Consignee")%>
                        </td>
                        <td class="col_telephone">
                            <%# Eval("Distributor.Telephone")%>
                        </td>
                        <td class="col_email">
                            <%# Eval("Distributor.Email")%>
                        </td>
                        <td class="col_house">
                            <%# Eval("DefalutHouse.Name") %>
                        </td>
                        <td class="col_op">
                            <uc:AuthorityControl runat="server" Action="Save">
                                <input type="button" class="icon-button-edit" value=" " onclick="modifyItem(<%# Eval("Distributor.ID") %>)"
                                    title="编辑" />
                            </uc:AuthorityControl>
                            <uc:AuthorityControl runat="server" Action="Delete">
                                <input type="button" class="icon-button-delete" value=" " onclick="deleteItem(<%# Eval("Distributor.ID") %>)"
                                    title="删除" />
                            </uc:AuthorityControl>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </table>
    </div>
    <asp:Literal ID="ltAllHouses" runat="server"></asp:Literal>
</asp:Content>
